﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Client
{
    public partial class frmManageApplication : Form
    {
        public frmManageApplication()
        {
            InitializeComponent();
        }

        private void radioButtonWord_CheckedChanged(object sender, EventArgs e)
        {
            if (radioButtonWord.Checked == true)
            {
                tb_Command.Text = radioButtonWord.Text;
                tb_Command.ReadOnly = true;
                txt_HuongDan.Visible = false;
            }
        }

        private void radioButtonPowerpoint_CheckedChanged(object sender, EventArgs e)
        {
            if (radioButtonPowerpoint.Checked == true)
            {
                tb_Command.Text = radioButtonPowerpoint.Text;
                tb_Command.ReadOnly = true;
                txt_HuongDan.Visible = false;
            }
        }

        private void radioButtonExcel_CheckedChanged(object sender, EventArgs e)
        {
            if (radioButtonExcel.Checked == true)
            {
                tb_Command.Text = radioButtonExcel.Text;
                tb_Command.ReadOnly = true;
                txt_HuongDan.Visible = false;
            }
        }

        private void radioButtonAccess_CheckedChanged(object sender, EventArgs e)
        {
            if (radioButtonAccess.Checked == true)
            {
                tb_Command.Text = radioButtonAccess.Text;
                tb_Command.ReadOnly = true;
                txt_HuongDan.Visible = false;
            }
        }

        private void radioButtonNotepad_CheckedChanged(object sender, EventArgs e)
        {
            if (radioButtonNotepad.Checked == true)
            {
                tb_Command.Text = radioButtonNotepad.Text;
                tb_Command.ReadOnly = true;
                txt_HuongDan.Visible = false;
            }
        }

        private void radioButtonPaint_CheckedChanged(object sender, EventArgs e)
        {
            if (radioButtonPaint.Checked == true)
            {
                tb_Command.Text = radioButtonPaint.Text;
                tb_Command.ReadOnly = true;
                txt_HuongDan.Visible = false;
            }
        }

        private void radioButtonTaskmanager_CheckedChanged(object sender, EventArgs e)
        {
            if (radioButtonTaskmanager.Checked == true)
            {
                tb_Command.Text = radioButtonTaskmanager.Text;
                tb_Command.ReadOnly = true;
                txt_HuongDan.Visible = false;
            }
        }

        private void radioButtonMore_CheckedChanged(object sender, EventArgs e)
        {
            if (radioButtonMore.Checked == true)
            {
                tb_Command.Text = "";
                tb_Command.ReadOnly = false;
                txt_HuongDan.Visible = true;
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void bt_Close_Click(object sender, EventArgs e)
        {
            foreach (System.Diagnostics.Process p in System.Diagnostics.Process.GetProcessesByName(tb_Command.Text))
            {
                try
                {
                    p.Kill();
                    p.WaitForExit(); // possibly with a timeout
                }
                catch (Win32Exception winException)
                {
                    // process was terminating or can't be terminated - deal with it
                }
                catch (InvalidOperationException invalidException)
                {
                    // process has already exited - might be able to let this one go
                }
            }
        }

        private void bt_Open_Click(object sender, EventArgs e)
        {
            try
            {
                //MessageBox.Show(tb_Command.Text);
                System.Diagnostics.Process proc = new System.Diagnostics.Process();
                proc.EnableRaisingEvents = false;


                proc.StartInfo.FileName = tb_Command.Text;
                proc.Start();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Can't open this application: '" + tb_Command.Text + "'");
            }
        }

        private void frmManageApplication_Load(object sender, EventArgs e)
        {

        }

    }
}
